package zdream.pmfield.data.foe;

import java.util.Arrays;
import java.util.Objects;

import zdream.pmfield.data.foe.MoveAdditionalEffects.EffectDescription;

/**
 * 特性, 包括其它所有的被动触发的技能
 *
 * @author Zdream
 * @date 2023-12-16
 * @since 0.0.1
 */
public class Ability {
	public static final String TAG_CUSTOMIZE = "customize";

	/**
	 * 中毒等特殊的 Ability 的 id 都是 0
	 */
	public final int id;
	public String name;
	public int level;
	public String[] tags;
	public String[] additions;

	public Ability(String[] contents) {
		this.id = 0;
	}

	public Ability(int id) {
		this.id = id;
	}

	public static Ability createCustomize(String... properties) {
		final Ability ability = new Ability(0);
		ability.level = 1;
		ability.tags = new String[] { Ability.TAG_CUSTOMIZE };
		ability.name = Ability.TAG_CUSTOMIZE;
		ability.additions = properties;
		return ability;
	}

	public EffectDescription[] createDescriptions() {
		if (additions == null) {
			return new EffectDescription[0];
		}

		return Arrays.stream(additions)
				.map(EffectDescription::of)
				.map(desc -> desc.withAbility(this))
				.toArray(EffectDescription[]::new);
	}

	public boolean is(String tag) {
		return Arrays.stream(tags).anyMatch(t -> Objects.equals(t, tag));
	}
}
